package com.colin.download.utils;

/**
 * Created by colin on 2018/2/5 14:05 .
 */

import android.content.Context;
import android.os.Environment;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;

/**
 * Created by 陈丰尧 on 2017/4/16.
 */

public class IOUtils {
	public static void closeIO(Closeable... closeables) {
		if (closeables != null) {
			for (Closeable closeable : closeables) {
				if (closeable != null) {
					try {
						closeable.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	/**
	 * 删除之前的apk
	 *
	 * @param apkName apk名字
	 * @return
	 */
	public static File clearApk(Context context, String apkName) {
		File apkFile = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), apkName);
		if (apkFile.exists()) {
			apkFile.delete();
		}
		return apkFile;
	}
}